package com.the4man.cnbdw.utils;

/**
 * Created by lenovo on 2017/12/12.
 */
public class PageUtil {
    private int currentPage = -1;
    private int pageSize = -1;
    private int startRows = -1;
    private int totalPage = -1;
    private int totalCnt = -1;

    private PageUtil() {
    }

    public static PageUtil build(int currentPage, int pageSize) throws IllegalArgumentException {
        if(pageSize < 1) {
            throw new IllegalArgumentException("pageSize 参数不能小于1");
        } else {
            PageUtil page = new PageUtil();
            page.setCurrentPage(currentPage);
            page.setPageSize(pageSize);
            int startRows = (currentPage - 1) * pageSize;
            page.setStartRows(startRows);
            return page;
        }
    }

    public static PageUtil build(int currentPage, int pageSize, int totalCnt) throws IllegalArgumentException {
        if(totalCnt < 0) {
            throw new IllegalArgumentException("totalCnt 参数不能小于1");
        } else {
            PageUtil page = build(currentPage, pageSize);
            page.setTotalCnt(totalCnt);
            int totalPage = (totalCnt + pageSize - 1) / pageSize;
            page.setTotalPage(totalPage);
            return page;
        }
    }

    public int getTotalPage() {
        return this.totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalCnt() {
        return this.totalCnt;
    }

    public void setTotalCnt(int totalCnt) {
        this.totalCnt = totalCnt;
    }

    public int getCurrentPage() {
        return this.currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartRows() {
        return this.startRows;
    }

    public void setStartRows(int startRows) {
        this.startRows = startRows;
    }
}
